import request from '../utils/request'

export const queryList = (params) => {
  return request({
    method: 'GET',
    url: 'modeler-app/rest/models',
    params: params
  })
}

export const queryDetail = (modelId, versionId) => {
  return request({
    method: 'GET',
    url: `modeler-app/rest/models/${modelId}${versionId ? `/history/${versionId}` : ''}`,
  })
}

export const createOne = (data) => {
  return request({
    method: 'POST',
    url: 'modeler-app/rest/models',
    data: data
  })
}

export const modifyOne = (id, data) => {
  return request({
    method: 'PUT',
    url: `modeler-app/rest/models/${id}`,
    data: data
  })
}

export const deleteOne = (id, params = {}) => {
  return request({
    method: 'DELETE',
    url: `modeler-app/rest/models/${id}`,
    params
  })
}

export const queryModelHistorys = (modelId) => {
  return request({
    method: 'GET',
    url: `modeler-app/rest/models/${modelId}/history`,
    params: {
      includeLatestVersion: true
    }
  })
}

export const useAsNewVersion = ({ modelId, versionId, ...data }) => {
  return request({
    method: 'POST',
    url: `modeler-app/rest/models/${modelId}/history/${versionId}`,
    data: data
  })
}

// 删除前查询模型是否有关联
export const queryModelParentRelation = (modelId) => {
  return request({
    method: 'GET',
    url: `modeler-app/rest/models/${modelId}/parent-relations`
  })
}

// 删除前查询模型是否有关联
export const cloneModel = (data) => {
  return request({
    method: 'POST',
    url: `modeler-app/rest/models/${data.id}/clone`,
    data
  })
}

